package com.aletto.general_store.presenters.views;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;

import com.aletto.general_store.data.model.Goods;
import com.aletto.general_store.ui.popup.GoodsBuyStatePopup;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.sisyphus.spinach.core.INetTask;

public class OrderGoodsBuyView implements INetTask.View<Object> {

    private final BasePopupView popupView;
    private final GoodsBuyStatePopup statePopup;

    public OrderGoodsBuyView(Context context, Goods goods, int number) {
        statePopup = new GoodsBuyStatePopup(context, goods, number);
        popupView = new XPopup.Builder(context).asCustom(statePopup);
    }

    @Override
    public void start() {
        popupView.show();
    }

    @Override
    public void success(Object data) {
        statePopup.playSuccess();
        new Handler(Looper.getMainLooper()).postDelayed(popupView::dismiss, 800);
    }

    @Override
    public void failure(Throwable throwable) {
        throwable.printStackTrace();
    }

    @Override
    public void complete() {
         popupView.dismiss();
    }

}
